home *** CD-ROM | disk | FTP | other *** search
- Path: nickel.as.arizona.edu!rwatkins
- From: rwatkins@nickel.as.arizona.edu (Ron Watkins)
- Newsgroups: comp.lang.c++
- Subject: Newbie question
- Date: 25 Mar 1996 17:26:10 GMT
- Organization: University of Arizona, Tucson, AZ
- Distribution: world
- Message-ID: <4j6kvi$l5a@news.ccit.arizona.edu>
- NNTP-Posting-Host: nickel.as.arizona.edu
- Keywords: memory
-
- I am experienced in C programming and trying to learn C++. I have a question
- though about how to make use of class types.
-
- In C, I can create a data structure and typedef a pointer to it (say a list).
- Then, the user can create as many pointers as he/she likes, then reference
- each one with functions to manipulate the data structures.
-
- In C++, using classes, I don't quite see how this is done. When I layout a
- list datatype, I get into the following situation:
-
- 1) Each occurance of the datatype creates a NEW list rather than linking more
- nodes onto an existing list.
-
- 2) I can't allow the user to have more than 1 occurance of my list because all
- usages of the class refer to the single static pointer in the class definition.
-
-
- Please help me out here. I just don't see how to mimic C's ability as follows:
- (please understand, this is quick typing, not copy/paste, so there may be
- slight syntax/semantic errors, im not worried about those, rather im interested
- in how to do somthing similar in C++)
-
-
- typedef struct LIST {
- char * value;
- struct LIST * next;
- } * list;
-
- func (list *) {
- /* manipulate list in some way */
- }
-
- /* in main (or other function) */
-
- list a, b;
- a = (list *) malloc (sizeof (struct LIST));
- b = (list *) malloc (sizeof (struct LIST));
-
- func (a);
- func (b);
-
- In C++, I have tried to create a class using static list and non static list.
- I continue to get the problems above.
-
- e-mail to rwatkins@as.arizona.edu
- --
- _
- |_) _ ._ \ / _._|_ | o._ _
- | \(_)| | \/\/ (_| |_ |<|| |_>
-
-